#!/usr/bin/env python
# -*- coding: utf-8 -*-
# author : wzp
# date : modify by wzp 20220513

import datetime
import sys,re
sys.path.append("./lib")
from dto import QueryMySQL
from WXBizMsgCrypt3 import WXBizMsgCrypt
from global_info import *
from chatGPT import send

def read(content):
    out_list = []
    if re.search("Q:",content,re.I):
        content = content.lstrip("Q:").lstrip("q:")
        result = QueryMySQL(content)
        if result:
            for content,date in result:
                out_list.append([content,date])
        else:
            print("[{}]查询数据无结果".format(content))
            out_list.append(["[{}]查询数据无结果".format(content),datetime.datetime.now()])

    elif re.search("C:",content,re.I):
        content = content.lstrip("C:").lstrip("c:")
        result =  send(content)
        if result :
            out_list.append([result,"喵~"])
            print(result)
        else:
            print("chatgpt没有查询结果")
            out_list.append(["[{}]chat查询数据无结果".format(content), datetime.datetime.now()])

    else:
        print("没有匹配命令")
        out_list.append([content,datetime.datetime.now()])

    return out_list


if __name__ == "__main__":
    content = "C:财务制度是什么意思？"
    read(content)
